<template>
	<div id="temp">
		<!-- 1.0 动态渲染新闻详情内容 -->
		<div class="title">
			<h4 v-text="desc.title"></h4>
			<p>{{desc.add_time | datefmt('YYYY-M-DD')}}  {{desc.click}}次浏览</p>
		</div>
		<div class="content" v-html="desc.content"></div>
		
		<!-- 2.0 评论区域 -->
		<comment :id="id"></comment>
	</div>
</template>

<script>
	//引入评论子组件
	import comment from '../subcom/comment.vue';
	export default {
		components: {
			comment
		},
		data() {
			return {
				id: 0, //默认为0
				desc: {}
			}
		},
		methods: {
			getDesc() {
				var url = this.$common.apidomain + '/api/getnew/' + this.id;
				this.$http.get(url).then(function (res) {
					//console.log(res.body.message[0]);
					//message本身是数组 里面的数据是对象 为了方便直接将对象赋给desc
					this.desc = res.body.message[0];
				});
			}
		},
		created() {
			//获取路由参数this.$route.params  (这里的参数id与路由规则配置的要一致)
			this.id = this.$route.params.id;
			this.getDesc();
		}
	}
</script>

<style scoped>
	.title h4 {
		color: #0094ff;
	}
	.title p {
		color: rgba(0, 0, 0, .5);
	}
	.title, .content {
		padding:5px;
	}
</style>